package com.huanletao.guava.it;

import com.google.common.collect.Sets;
import org.junit.Test;

import java.util.Set;

public class demo1 {
    public static void main(String[] args) {
      testSets();
    }
    @Test
    public static void testSets() {
        Set<Integer> set1 = Sets.newHashSet(1, 2, 4, 5, 6, 8);
        Set<Integer> set2 = Sets.newHashSet(2, 4, 5, 6);

        //合集，并集   [1, 2, 4, 5, 6, 8, 3, 7, 9]
        Set<Integer> result1 = Sets.union(set1, set2);
        //交集          [2, 4, 5, 6]
        Set<Integer> result2 = Sets.intersection(set1, set2);
        //差集 1中有而2中没有的  [1, 8]
        Set<Integer> result3 = Sets.difference(set1, set2);
        //相对差集 1中有2中没有  2中有1中没有的 取出来做结果 [1, 8, 3, 7, 9]
        Set<Integer> result4 = Sets.symmetricDifference(set1, set2);

        System.out.println(result1);
        System.out.println(result2);
        System.out.println(result3);
        System.out.println(result4);

    }
}
